#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,mod=998244353;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int n,a[N],b[N],s[N],ans,tp,mx,sum;
map<vector<int>,bool> mp; 

void dfs(int pos){
	if(pos==n+1){
		vector<int> p;
		for(int i=1;i<=n;i++) b[i]=a[i];
		for(int i=1;i<=n;i++){
			b[i]-=s[i];
			b[i%n+1]+=s[i];
		}
		for(int i=1;i<=n;i++)
			if(!b[i]) return;
		for(int i=1;i<=n;i++) p.push_back(b[i]);
		if(!mp[p]){
			mp[p]=1;
			int res=1;
			for(int i=1;i<=n;i++)
				res=(res*b[i])%mod;
			ans=(ans+res)%mod;
		}
		return;
	}
	for(int i=0;i<=a[pos];i++){
		s[++tp]=i;
		dfs(pos+1);
		tp--;
	}
}

signed main(){
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	n=read();
	if(!n){
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++) a[i]=read(),mx=max(mx,a[i]),sum+=a[i];
	if(n<=30){
		dfs(1);
		cout<<ans;
	}
	else if(mx<=1){
		if(sum==n) cout<<1;
		else cout<<0;
	}
	return 0;
}